package com.itianyu.blog.validation;

import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import com.itianyu.blog.dao.beans.Entry;

/**
 * 博文校验
 * @author wumgji
 */
@Component("EntryValidator")
public class EntryValidator implements Validator {

	@Override
	@SuppressWarnings("rawtypes")
	public boolean supports(Class classToValidate) {
		return Entry.class.equals(classToValidate);
	}

	@Override
	public void validate(Object obj, Errors errs) {
		ValidationUtils.rejectIfEmptyOrWhitespace(errs, "title", "field.required");
		ValidationUtils.rejectIfEmpty(errs, "body", "field.required");
	}

}
